#include "textureLoader.h"

TextureLoader::TextureLoader(GLint wrap_s,GLint wrap_t,GLint mag_filter,GLint min_filter){
	_wrap_s = wrap_s;
	_wrap_t = wrap_t;
	_mag_filter = mag_filter;
	_min_filter = min_filter;
	loaded=false;
}

TextureLoader::~TextureLoader(){

}

void TextureLoader::load(Texture& tex){
	if(!loaded){
		glGenTextures(1,&_id );
		glBindTexture(GL_TEXTURE_2D,_id);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,_wrap_s);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,_wrap_t);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,_mag_filter);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,_min_filter);

		if(tex.ctype()==Texture::RGBA)
			glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,tex.width(),tex.height(),0,GL_RGBA,GL_UNSIGNED_BYTE,tex.data());
		else
			glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,tex.width(),tex.height(),0,GL_RGB,GL_UNSIGNED_BYTE,tex.data());

		loaded=true;
	}
}
